package com.example.demo.generator.scaffold.controller;

import com.example.demo.common.BaseResponse;
import com.example.demo.common.PageResult;
import com.example.demo.common.ResultUtils;
import com.example.demo.generator.scaffold.dto.log.ScaffoldLogListRequest;
import com.example.demo.generator.scaffold.dto.log.ScaffoldLogRecord;
import com.example.demo.generator.scaffold.service.ScaffoldGenerationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 脚手架生成日志查询接口。
 */
@RestController
@RequestMapping("/generator/scaffold/logs")
@RequiredArgsConstructor
@Validated
@ConditionalOnProperty(prefix = "feature.database", name = "enabled", havingValue = "true")
@Tag(name = "脚手架日志", description = "查询脚手架生成记录")
public class ScaffoldLogController {

    private final ScaffoldGenerationLogService logService;

    @PostMapping("/list")
    @PreAuthorize("hasAnyRole('ADMIN','USER')")
    @Operation(summary = "分页查询生成日志", description = "支持按关键词模糊匹配模块名称、基础包与目录")
    public BaseResponse<PageResult<ScaffoldLogRecord>> list(@Valid @RequestBody ScaffoldLogListRequest request) {
        return ResultUtils.success(logService.listLogs(request));
    }
}


